var Md5 = require('../../utils/md5.js');
var timeSecond = Math.floor(Date.now() * 0.001);  //获取时间戳: 
var SignInfoData = Md5.hexMD5(timeSecond + 'nativetalk')//md5加密;
var WxParse = require('../../wxParse/wxParse.js');
const app = getApp();
var httpNativetalk = app.globalData.httpNativetalk;
var httpWeike = app.globalData.httpWeike;
var pageNum = 1, systemDataArr = [], totalPage;
Page({
  data: {
    imgUrl: 'http://file.waijiaojun.com/waijiaojun/icon',
  },
  onLoad: function (e) {
    this.systemData(pageNum);    
  },
  onShow: function (e) {
  },
//课程的数据请求
  systemData: function (pageNum) {
    console.log("发起数据请求", systemDataArr);
    if (app.globalData.token !== null) {
      var that = this;
      wx.request({
        url: httpWeike + '/v4.2/student/token/my/weike',
        data: {
          "currentPage": pageNum,
          "pageSize": 10,
        },
        header: {
          "Timestamp": timeSecond,
          "SignInfo": SignInfoData,
          "content-Type": "application/json",
          "client_type": "3",
          "version": 15,
          'token': app.globalData.token,
        },
        method: 'POSt',
        success: function (res) {
          console.log(res);
          var systemClassData = res.data.obj.data;
          totalPage = res.data.obj.totalPage;
          if (systemClassData.length == 0) {
            that.setData({
              systemDataArr: '',
            })
          }
          if (systemClassData.length !== 0) {
            console.log(123)
            systemDataArr.push(res.data.obj.data)
            for (var i = 0; i < systemClassData.length; i++) {
              systemClassData[i].cover_url = 'http://file.waijiaojun.com/' + systemClassData[i].cover_url;
              systemClassData[i].teacher_avatar_url = 'http://file.waijiaojun.com/' + systemClassData[i].teacher_avatar_url;
            }
            that.setData({
              systemDataArr: systemDataArr,
              systemClassData: systemClassData,
            })
          }
        },
        fail: function (res) { },
        complete: function (res) { },
      })
    }
  },
  onReachBottom: function () {
    pageNum++;
    console.log("faqiqinqiu", pageNum, totalPage)
    if (pageNum > 1 && pageNum <= totalPage) {
      console.log(pageNum)
      this.systemData(pageNum)
    }
  },
  onUnload:function(e){
    pageNum=1;
    systemDataArr=[];    
  },
  CommentFun: function (e) {
    var weikeIds = e.currentTarget.dataset.weikeid;
    wx.navigateTo({
      url: '/pages/systemClass/systemClass?weikeId=' + weikeIds,
    })
  }

})